/**
 * 
 */
package nl.sportan.samenloop.adapter;

import java.util.ArrayList;

import nl.sportan.samenloop.CameraActivity;
import nl.sportan.samenloop.CinemaActivity;
import nl.sportan.samenloop.FlickrActivity;
import nl.sportan.samenloop.ProgramActivity;
import nl.sportan.samenloop.R;
import nl.sportan.samenloop.SamenLoopInfoActivity;
import nl.sportan.samenloop.TwitterActivity;
import nl.sportan.samenloop.model.Tile;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * @author Bram Wiekens
 *
 */
public class TileAdapter  extends BaseAdapter {

	private ArrayList<Tile> tiles;
	private Context context;
	
	
	public TileAdapter(Context context) {
		this.context = context;
		tiles = new ArrayList<Tile>();
		
		Tile twitter = new Tile(R.drawable.twitter, context.getResources().getString(R.string.twitter));
		twitter.setActivity(TwitterActivity.class);
		
		Tile flickr = new Tile(R.drawable.photo, context.getResources().getString(R.string.flickr));
		flickr.setActivity(FlickrActivity.class);
		
		Tile video = new Tile(R.drawable.video, context.getResources().getString(R.string.video));
		video.setActivity(CinemaActivity.class);
		
		Tile program = new Tile(R.drawable.news, context.getResources().getString(R.string.news));
		program.setActivity(ProgramActivity.class);
		
		Tile info = new Tile(R.drawable.teams, context.getResources().getString(R.string.teams));
		info.setActivity(SamenLoopInfoActivity.class);
		
		Tile location = new Tile(R.drawable.mile, context.getResources().getString(R.string.mile));
		location.setActivity(SamenLoopInfoActivity.class);
		
		tiles.add(twitter);
		tiles.add(flickr);
		tiles.add(video);
		tiles.add(program);
		tiles.add(info);
		tiles.add(location);
	}
	
	
	
	public int getCount() {
		return tiles.size();
	}

	public Object getItem(int position) {
		return tiles.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout vp = new LinearLayout(context);
		vp.setOrientation(LinearLayout.VERTICAL);
		
		TextView t = new TextView(context);
		t.setGravity(Gravity.CENTER_HORIZONTAL);
		
		t.setText(tiles.get(position).getDescription());
		
		ImageView i = new ImageView(context);
		 i.setImageResource(tiles.get(position).getDrawableId());

		 vp.addView(i);
		 vp.addView(t);
		 
		 return vp;
	}

	
	
}
